// pages/news_detail/news_detail.js
var app = getApp();
//引入这个插件，使html内容自动转换成wxml内容
var WxParse = require('../../wxParse/wxParse.js');
Page({
  data: {
    newid: 0,
    getimg: '',
    news_title: "", //标题
    news_author: "", //作者
    news_from: "", //来源
    news_time: [], //时间
  },

  //事件处理函数
  bindViewTap: function () {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },

  onLoad: function (option) {
    var that = this;
    that.setData({
      newid: option.newid,
    });
    that.loadDetail();
  },
  loadDetail: function () {
    var that = this;
    wx.request({
      url: app.d.hostUrl + '/api/system/getGonggaoDetail',
      method: 'post',
      data: {
        id: that.data.newid,
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res);
        // --init data 
        var news_title = res.data.data.title;
        var news_author = res.data.data.editor;
        var news_time = res.data.data.ctime;
        var prev = res.data.prev;
        var next = res.data.next;
        var news_detail = res.data.data.content;
        WxParse.wxParse('news_detail', 'html', news_detail, that, 0);
        that.setData({
          news_title: news_title,
          news_author: news_author,
          news_time: news_time,
          prev: prev,
          next: next,
        });
      },
      error: function (e) {
        wx.showToast({
          title: '网络异常！',
          duration: 2000,
        });
      },

    });
  },

  // 拨打电话
  opentel: function () {
    app.gotel();
  },

  /**
 * 用户点击右上角分享
 */
  onShareAppMessage: function () {
    var openid = wx.getStorageSync('openid');
    from: menu;
    return {
      title: '走吧商城',
      path: '/pages/onepage/onepage?openid=' + openid,
      success: function (res) {
        // console.log(openid);      
      },
      fail: function (res) {
        // console.log(res);
      }
    }
  },


})
